package com.log320.huffman;

import java.util.Comparator;
/**
 * Simple comparator that compares two binary code by their desired code length.
 *
 */
public class BinaryCodeDesiredCodeLengthComparator implements Comparator<BinaryCode>{

	@Override
	public int compare(BinaryCode bin1, BinaryCode bin2) {
		int value;
		if(bin1.getDesiredCodeLength()<bin2.getDesiredCodeLength()){
			value=-1;
		}else if(bin1.getDesiredCodeLength()>bin2.getDesiredCodeLength()){
			value=1;
		}else{
			if(bin1.getCharacter()<bin2.getCharacter()){
				value=-1;
			}else
				value=1;
		}
		
		return value;
	}
	
}
